package com.medical.data.controller;

import com.medical.data.domain.HospitalInformation;
import com.medical.data.domain.User;
import com.medical.data.domain.UserPermission;
import com.medical.data.service.HospitalInformationService;
import com.medical.data.service.UserPermissionService;
import com.medical.data.utils.Result;
import com.medical.data.vo.GetJoinUserVo;
import com.medical.data.vo.HospitalVo;
import com.medical.data.vo.JoinUserVo;
import com.medical.data.vo.UserPermissionsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@Api(description = "多用户管理")
@RequestMapping("/front/multiUser")
@RestController
@Slf4j
public class MultiUserController {

    @Autowired
    private UserPermissionService userPermissionService;

    @ApiOperation("申请加入他人项目")
    @PostMapping("/joinProject/{projectId}")
    public Result joinProject(@PathVariable @NotBlank String projectId) {
        log.info("/front/multiUser/joinProject========>{}", projectId);
        userPermissionService.joinProject(projectId);
        return Result.ok();
    }

    @ApiOperation("获取申请加入的列表")
    @PostMapping("/getJoinUser")
    public Result getJoinUser(@RequestBody GetJoinUserVo getJoinUserVo) {
        log.info("/front/multiUser/getJoinUser========>{}", getJoinUserVo);
        Map<String, Object> map = userPermissionService.getJoinUser(getJoinUserVo);
        return Result.ok().data(map);
    }

    @ApiOperation("同意用户加入项目")
    @PostMapping("/agreeUser/{projectId}/{userId}")
    public Result agreeUser(@PathVariable @NotBlank String projectId,@PathVariable @NotBlank String userId) {
        log.info("/front/multiUser/agreeUser========>{}", projectId,userId);
        userPermissionService.agreeUser(projectId,userId);
        return Result.ok();
    }

    @ApiOperation("拒绝用户加入项目")
    @PostMapping("/refuseUser/{projectId}/{userId}")
    public Result refuseUser(@PathVariable @NotBlank String projectId,@PathVariable @NotBlank String userId) {
        log.info("/front/multiUser/refuseUser========>{}", projectId,userId);
        userPermissionService.refuseUser(projectId,userId);
        return Result.ok();
    }

    @ApiOperation("将他人移出项目")
    @PostMapping("/removeUser/{projectId}/{userId}")
    public Result removeUser(@PathVariable @NotBlank String projectId,@PathVariable @NotBlank String userId) {
        log.info("/front/multiUser/removeUser========>{}", projectId,userId);
        userPermissionService.removeUser(projectId,userId);
        return Result.ok();
    }

    @ApiOperation("获取项目参与者列表")
    @PostMapping("/getProjectUser")
    public Result getProjectUser(@RequestBody @Validated GetJoinUserVo getJoinUserVo) {
        log.info("/front/multiUser/getProjectUser========>{}", getJoinUserVo);
        Map<String,Object>map = userPermissionService.getJoinedProjectUser(getJoinUserVo);
        return Result.ok().data(map);
    }

    @ApiOperation("给参与者分配或更改已有权限")
    @PostMapping("/assignPermissions")
    public Result assignPermissions(@RequestBody @NotNull UserPermissionsVo userPermissionsVo) {
        log.info("/front/multiUser/assignPermissions========>{}", userPermissionsVo);
        userPermissionService.assignPermissions(userPermissionsVo);
        return Result.ok();
    }

    @ApiOperation("查看用户已有权限")
    @PostMapping("/getUserPermissions/{projectId}/{userId}")
    public Result getUserPermissions(@PathVariable @NotBlank String projectId,@PathVariable @NotBlank String userId) {
        log.info("/front/multiUser/getUserPermissions========>{}", projectId,userId);
        Map<String,Boolean>map=userPermissionService.getUserPermissions(projectId,userId);
        return Result.ok().data("result",map);
    }

}

